/******************************************

@Author :yinjinlin<yinjinlin_uplook@163.com>
@Time : 2020/11/18 下午1:09

*******************************************/
package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/risk"
	risk2 "git.900sui.cn/kc/rpcinterface/interface/risk"
	"git.900sui.cn/kc/rpcinterface/interface/task/insurance"
	"github.com/streadway/amqp"
)

func main(){

	//  -- 入口  ===== ---初始化出口
	rpcbbaa := new(risk.BusBasicAccumulative).Init()
	defer rpcbbaa.Close()

	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("insurance.log.setInsuranceRate"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("insurance.queue.setInsuranceRate"),func(msg amqp.Delivery){
		var res insurance.ArgsInsuranceRate
		if err := json.Unmarshal(msg.Body, &res); err != nil{
			return
		}

		var reply bool
		// 投保率
		if err := rpcbbaa.AddInsuranceRateRpc(context.Background(), &risk2.ArgsInsuranceStatic{RelationId: res.RelationId,
			CardPackageId: res.CardPackageId,
			CardPackageType: res.CardPackageType,
		}, &reply ); err != nil {
			utils.Logerr.Printf("统计企业投保率任务错误 relation: %d error: %s\n",res.RelationId, err.Error())
		}
		utils.Logerr.Printf("统计企业投保率任务成功 relation: %d",res.RelationId)

	})

	if err != nil {
		utils.Logerr.Printf("统计企业投保率任务失败 err: %s",err.Error())
	}
}
